/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package org.dusin.teachassistdbservice.util;

import com.google.gson.Gson;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author dusin
 */
public class JsonUtil {
    public static String toDatagrid(List list){
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("total", list.size());
        map.put("rows", list);
        Gson gson = new Gson();
        String result = gson.toJson(map);
        return result;
    }
    public static String successJson(String msg){
         return failOrSuccessJson(true,msg);
    }
    
    public static String failJson(String msg){
        return failOrSuccessJson(false,msg);
    }
    public static String failOrSuccessJson(boolean isSuccessful,String msg){
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("success", isSuccessful);
        map.put("msg",msg);
        Gson gson = new Gson();
        String result = gson.toJson(map);
        return result;
    }
    
}
